package so.wy.servicecenter.businessbed.api.pay;

import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import so.wy.servicecenter.base.exception.WebException;
import so.wy.servicecenter.base.frame.api.AbstractHttp;
import so.wy.servicecenter.businessbed.web.pay.PayResultWeb;

@RestController
@Scope("request")
@RequestMapping("/pay/notify")
public class PayResultHttp extends AbstractHttp {
    @Autowired
    private PayResultWeb payResultWeb;

    //支付结果回调
    @PostMapping("/order")
    public String  handPayResult(@RequestBody String xmlData)   {
        try {
            payResultWeb.handPayResult(xmlData);
            return WxPayNotifyResponse.success("成功");
        } catch (WebException e) {
            return WxPayNotifyResponse.fail("失败");
        }
    }

    //退款结果回调
    @PostMapping("/refund")
    public String handRefundResult(@RequestBody String xmlData){
        try {
            payResultWeb.handRefundResult(xmlData);
            return WxPayNotifyResponse.success("成功");
        } catch (WebException e) {
            return WxPayNotifyResponse.fail("成功");
        }
    }

}
